<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    <title> - 天地维杰网</title>
    <meta name="keywords" content="系统架构,shutdown,不与天斗,Domino,博客,程序员,架构师,笔记,技术,分享,java,Redis">
    
    <meta property="og:title" content="">
    <meta property="og:site_name" content="天地维杰网">
    <meta property="og:image" content="/img/author.jpg"> 
    <meta name="title" content=" - 天地维杰网" />
    <meta name="description" content="天地维杰网 | 博客 | 软件 | 架构 | Java "> 
    <link rel="shortcut icon" href="http://www.shutdown.cn/img/favicon.ico" />
    <link rel="apple-touch-icon" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link rel="apple-touch-icon-precomposed" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link href="http://www.shutdown.cn/js/vendor/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/main.css" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/syntax.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
     fancybox: true, 
    motion: true
  };
</script>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left page-home  ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-meta  custom-logo ">

  <div class="custom-logo-site-title">
    <a href="http://www.shutdown.cn"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天地维杰网</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">人如秋鸿来有信，事若春梦了无痕</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
    <ul id="menu" class="menu">
      
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/redis/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-full"></i> <br />Redis
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/java/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-coffee"></i> <br />java
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/linux/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-linux"></i> <br />linux
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/daily/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bug"></i> <br />日常问题
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-child"></i> <br />Spring和Springboot
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-fire"></i> <br />Mac相关
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/middleware/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-gavel"></i> <br />中间件
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jiagou/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-rocket"></i> <br />架构
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/python/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-ship"></i> <br />python
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/front/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bolt"></i> <br />前端
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jvm/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-balance-scale"></i> <br />JVM
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/post/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/about/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于
          </a>
        </li>
      
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger"> <i class="menu-item-icon fa fa-search fa-fw"></i> <br /> 搜索</a>
      </li>
    </ul>
    <div class="site-search">
      <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>

    </div>
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
<section id="posts" class="posts-expand">
  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/jvm%E5%AD%A6%E4%B9%A002-%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%9A%84%E5%9F%BA%E6%9C%AC%E7%BB%93%E6%9E%84/" itemprop="url">
        
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="0001-01-01">
    0001-01-01
</time>
</span> 
      
      
       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">1251 字 ~6分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    

    

<h1 id="jvm学习02-虚拟机的基本结构">JVM学习02-虚拟机的基本结构</h1>

<h2 id="1-虚拟机的基本结构">1.虚拟机的基本结构</h2>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/1620268925957-20210506104205.png" width = 600 /> </div>

<p>虚拟机的结构可以参考 <a href="https://docs.oracle.com/javase/specs/index.html">java虚拟机规范</a> 进行理解</p>

<ul>
<li>类加载子系统</li>
</ul>

<p>加载类信息（class）到方法区</p>

<ul>
<li>方法区</li>
</ul>

<p>存放类信息、运行时常量池信息（字符串和数字常量）</p>

<ul>
<li>java堆</li>
</ul>

<p>虚拟机启动时建立的内存工作区域，存放几乎所有java对象实例，所有线程共享。</p>

<ul>
<li>直接内存（NIO）</li>
</ul>

<p>java堆外的直接向系统申请的内存，可以由java的NIO库进行操作。速度优于java堆，适用于频繁读写，不受Xmx最大内存限制，受操作系统最大内存限制</p>

<ul>
<li>垃圾回收系统</li>
</ul>

<p>可以对方法区、java堆和直接内在进行回收。重点回收java堆。</p>

<ul>
<li>java栈</li>
</ul>

<p>每个java虚拟机线程都有一个私有的java栈，在线程被创建的时候创建。java栈中保存着栈帧信息，还保存着局部变量、方法参数，与java方法的调用 、返回密切相关。</p>

<ul>
<li>本地方法栈</li>
</ul>

<p>java虚拟机的重要扩展，本地方法（通常C编写 ）</p>

<ul>
<li>Program Counter 程序计数器/PC寄存器</li>
</ul>

<p>程序计数器也是线程私有空间。</p>

<ul>
<li>执行引擎</li>
</ul>

<p>核心组件，执行虚拟机字节码。</p>

<h2 id="2-堆空间结构">2.堆空间结构</h2>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/1620271736038-20210506112855.png" width = 600 /> </div>

<p>堆空间分为新生代和老年代</p>

<ul>
<li><p>新生代：新生对象或年龄不大的对象</p>

<ul>
<li>eden区</li>
</ul>

<p>对象首先分配在eden区，新生代回收后，如果对象还存活，则会进入 s0或者s1区</p>

<ul>
<li>s0区（from区)和s1区（to区），大小相等的两块，可以互换角色的内存空间</li>
</ul>

<p>每经一次新生代回收，存活的对象的年龄会加1，达到一定条件后会被认为是老年对象进入老年区。</p>

<p>（问题，判定老年对象的条件是什么）</p></li>

<li><p>老年代</p></li>
</ul>

<p>堆、方法区、栈的关系</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/1620272206060-20210506113645.png" width = 600 /> </div>

<h2 id="3-函数调用与java栈">3.函数调用与java栈</h2>

<p>线程的执行的基本行为是函数调用，每次函数调用的数据都是通过java栈传递。java栈的主要内容是栈帧，每次函数调用都会有栈帧压入java栈，函数调用结束栈帧被弹出java栈。</p>

<p>函数返回时，栈帧从java栈中弹出。java方法有两种返回函数的方式，一种是return，一种是抛出异常。一个栈帧中至少要包含局部变量表、操作数栈和栈帧数据区几个部分。</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/1620624421294-20210510132700.png" width = 600 /> </div>

<p>由于每次函数调用都会生成对应的栈帧，所以会占用栈空间，因此，如果栈空间不足，那函数调用无法继续进行下去，当请求的栈尝试大于最大可用栈深度时，系统就会抛出StackOverFlowError栈溢出错误。可以使用参数 -Xss来指定线程的最大栈空间，这个参数决定了函数的最大的调用深度。函数嵌套调用的层次，取决于栈空间的大小，栈越大，函数就可以嵌套越多次。</p>

<ul>
<li>局部变量表</li>
</ul>

<p>保存函数的参数及局部变量。</p>

<p>ps：相同的栈容量下，局部变量少的函数，可以支持更深的函数调用，如果函数的参数和局部变量较多，会使局部变量表膨胀，导致函数嵌套次数变少。</p>

<p>栈帧中的局部量变量中的槽位是可以重用的，局部变量过了作用域，后续新申请的局部变量可能会复用过作用域的局部变量的槽位，用以节约资源。</p>

<p>以下代码来测试局部变量与垃圾回收关系</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">  <span style="color:#8f5902;font-style:italic">/**
</span><span style="color:#8f5902;font-style:italic">   *
</span><span style="color:#8f5902;font-style:italic">   * 测试变量的GC结果
</span><span style="color:#8f5902;font-style:italic">   * 执行时增加jvm参数  -XX:+PrintGC
</span><span style="color:#8f5902;font-style:italic">   * @author domino
</span><span style="color:#8f5902;font-style:italic">   * @date 2021/5/17
</span><span style="color:#8f5902;font-style:italic">   */</span>
  <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">TestLocalVariable</span> <span style="color:#ce5c00;font-weight:bold">{</span>
  
      <span style="color:#8f5902;font-style:italic">/**
</span><span style="color:#8f5902;font-style:italic">       * 有引用指向变量不会被回收
</span><span style="color:#8f5902;font-style:italic">       */</span>
      <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">localVarGc1</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
          <span style="color:#204a87;font-weight:bold">byte</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#ce5c00;font-weight:bold">]</span> <span style="color:#000">a</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#204a87;font-weight:bold">byte</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#000">6</span> <span style="color:#ce5c00;font-weight:bold">*</span> <span style="color:#000">1024</span> <span style="color:#ce5c00;font-weight:bold">*</span> <span style="color:#000">1024</span><span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">gc</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
      <span style="color:#ce5c00;font-weight:bold">}</span>
  
      <span style="color:#8f5902;font-style:italic">/**
</span><span style="color:#8f5902;font-style:italic">       * 无引用指向变量被回收
</span><span style="color:#8f5902;font-style:italic">       */</span>
      <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">localVarGc2</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
          <span style="color:#204a87;font-weight:bold">byte</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#ce5c00;font-weight:bold">]</span> <span style="color:#000">a</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#204a87;font-weight:bold">byte</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#000">6</span> <span style="color:#ce5c00;font-weight:bold">*</span> <span style="color:#000">1024</span> <span style="color:#ce5c00;font-weight:bold">*</span> <span style="color:#000">1024</span><span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#000">a</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">gc</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
      <span style="color:#ce5c00;font-weight:bold">}</span>
  
      <span style="color:#8f5902;font-style:italic">/**
</span><span style="color:#8f5902;font-style:italic">       * 虽然变量超过作用域，但是变量仍存在于局部变量表中，并且也指向数组，所以不会被立即回收
</span><span style="color:#8f5902;font-style:italic">       */</span>
      <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">localVarGc3</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
          <span style="color:#ce5c00;font-weight:bold">{</span>
              <span style="color:#204a87;font-weight:bold">byte</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#ce5c00;font-weight:bold">]</span> <span style="color:#000">a</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#204a87;font-weight:bold">byte</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#000">6</span> <span style="color:#ce5c00;font-weight:bold">*</span> <span style="color:#000">1024</span> <span style="color:#ce5c00;font-weight:bold">*</span> <span style="color:#000">1024</span><span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#ce5c00;font-weight:bold">}</span>
          <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">gc</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
      <span style="color:#ce5c00;font-weight:bold">}</span>
  
      <span style="color:#8f5902;font-style:italic">/**
</span><span style="color:#8f5902;font-style:italic">       * a变量超过了作用域，a变量失效，新建变量c，使用了a变量的字，a变量被销毁，垃圾回收可以正常回收数组
</span><span style="color:#8f5902;font-style:italic">       */</span>
      <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">localVarGc4</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
          <span style="color:#ce5c00;font-weight:bold">{</span>
              <span style="color:#204a87;font-weight:bold">byte</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#ce5c00;font-weight:bold">]</span> <span style="color:#000">a</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#204a87;font-weight:bold">byte</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#000">6</span> <span style="color:#ce5c00;font-weight:bold">*</span> <span style="color:#000">1024</span> <span style="color:#ce5c00;font-weight:bold">*</span> <span style="color:#000">1024</span><span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#ce5c00;font-weight:bold">}</span>
          <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">c</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">10</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">gc</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
      <span style="color:#ce5c00;font-weight:bold">}</span>
  
      <span style="color:#8f5902;font-style:italic">/**
</span><span style="color:#8f5902;font-style:italic">       * 调用 localVarGc1 方法以后，localVarGc1的栈帧被销毁，栈帧中的局部变量被销毁，所以可以正常垃圾回收
</span><span style="color:#8f5902;font-style:italic">       */</span>
      <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">localVarGc5</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
          <span style="color:#000">localVarGc1</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">gc</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
      <span style="color:#ce5c00;font-weight:bold">}</span>
  
      <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">main</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#ce5c00;font-weight:bold">]</span> <span style="color:#000">args</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
          <span style="color:#000">TestLocalVariable</span> <span style="color:#000">t1</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">TestLocalVariable</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
  <span style="color:#8f5902;font-style:italic">//        t1.localVarGc1();
</span><span style="color:#8f5902;font-style:italic"></span>  <span style="color:#8f5902;font-style:italic">//        t1.localVarGc2();
</span><span style="color:#8f5902;font-style:italic"></span>  <span style="color:#8f5902;font-style:italic">//        t1.localVarGc3();
</span><span style="color:#8f5902;font-style:italic"></span>  <span style="color:#8f5902;font-style:italic">//        t1.localVarGc4();
</span><span style="color:#8f5902;font-style:italic"></span>          <span style="color:#000">t1</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">localVarGc5</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
      <span style="color:#ce5c00;font-weight:bold">}</span>
  <span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<p>方法1到方法5的运行结果如下，可以结合方法注释来看结果原因。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">  ----------------------
  [GC (System.gc())  10080K-&gt;6824K(251392K), 0.0048977 secs]
  [Full GC (System.gc())  6824K-&gt;6599K(251392K), 0.0056204 secs]
  ----------------------
  [GC (System.gc())  16676K-&gt;6831K(251392K), 0.0008493 secs]
  [Full GC (System.gc())  6831K-&gt;411K(251392K), 0.0045246 secs]
  ----------------------
  [GC (System.gc())  10487K-&gt;6619K(251392K), 0.0010462 secs]
  [Full GC (System.gc())  6619K-&gt;6555K(251392K), 0.0041690 secs]
  ----------------------
  [GC (System.gc())  14010K-&gt;6555K(251392K), 0.0003860 secs]
  [Full GC (System.gc())  6555K-&gt;411K(251392K), 0.0036868 secs]
  ----------------------
  [GC (System.gc())  9177K-&gt;6651K(251392K), 0.0011968 secs]
  [Full GC (System.gc())  6651K-&gt;6555K(251392K), 0.0050845 secs]
  [GC (System.gc())  6555K-&gt;6555K(251392K), 0.0005586 secs]
  [Full GC (System.gc())  6555K-&gt;411K(251392K), 0.0042518 secs]</code></pre></div>
<blockquote>
<p>使用工具jclasslib可以查看函数的中变量的作用域、槽位的索引、变量名、数据类型等等，这个文档写着比较麻烦，后面补充</p>
</blockquote>

<ul>
<li>操作数栈</li>
</ul>

<p>用于保存计算过程的中间结果，同时作为计算过程中变量临时的存储空间。</p>

<ul>
<li>帧数据区</li>
</ul>

<p>栈帧用来支持常量池解析、正常方法返回和异常处理等的数据</p>

<ul>
<li>帧数据区中保存着常量池的指针，方便程序访问常量池。<font color=red>（疑问：常量池在什么区？）</font></li>

<li><p>异常处理表是帧数据区中重要部分，在处理异常时，虚拟机必须有一个异常处理表方便发生异常时找到处理的代码。</p></li>

<li><p>栈上分配</p></li>
</ul>

<p>java虚拟机优化技术，将线程私有对象分配到栈上，不分配到堆，函数调用后自行销毁，不需要垃圾回收提高性能。</p>

<p>栈上分配的技术基础是逃逸分析，判断对象的作用域是否能逃出函数体。如果不能，可能被分配到栈上而不在堆上。</p>

<p>测试代码:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">  <span style="color:#8f5902;font-style:italic">/**
</span><span style="color:#8f5902;font-style:italic">   * 本类测试栈上分配，逃逸分析，局部变量范围未超出函数体可能会被分配到栈而不是堆
</span><span style="color:#8f5902;font-style:italic">   *
</span><span style="color:#8f5902;font-style:italic">   * 执行方法要加以下jvm参数
</span><span style="color:#8f5902;font-style:italic">   * -server -Xmx10m -Xms5m -XX:+DoEscapeAnalysis -XX:+PrintGC -XX:-UseTLAB -XX:+EliminateAllocations
</span><span style="color:#8f5902;font-style:italic">   * 说明：
</span><span style="color:#8f5902;font-style:italic">   * -server server模式下才会启用逃逸分析
</span><span style="color:#8f5902;font-style:italic">   * -Xmx10m 指定堆空间最大内存为10M
</span><span style="color:#8f5902;font-style:italic">   * -XX:+DoEscapeAnalysis 启用逃逸分析
</span><span style="color:#8f5902;font-style:italic">   * -XX:+PrintGC 打印GC日志
</span><span style="color:#8f5902;font-style:italic">   * -XX:-UseTLAB 关闭TLAB Thread Local Allocation Buffer 线程本地分配缓存
</span><span style="color:#8f5902;font-style:italic">   * -XX:+EliminateAllocations 开启标量替换（默认是打开的），允许将对象打散分配到栈上，如对象拥有id和name
</span><span style="color:#8f5902;font-style:italic">   *      这两人个变量将被视为两个独立的局部变量进行分配
</span><span style="color:#8f5902;font-style:italic">   * 执行结果
</span><span style="color:#8f5902;font-style:italic">   * [GC (Allocation Failure)  1023K-&gt;565K(5632K), 0.0012699 secs]
</span><span style="color:#8f5902;font-style:italic">   * [GC (Allocation Failure)  1589K-&gt;613K(6656K), 0.0015624 secs]
</span><span style="color:#8f5902;font-style:italic">   * 9
</span><span style="color:#8f5902;font-style:italic">   *  GC (Allocation Failure) ： 发生了一次垃圾回收，若前面有Full则表明是Full GC，没有Full的修饰表明这是一次Minor GC
</span><span style="color:#8f5902;font-style:italic">   *  。注意它不表示只GC新生代，括号里的内容是gc发生的原因，这里的Allocation Failure的原因是年轻代中没有足够区域能够存放需要分配的数据而失败，。
</span><span style="color:#8f5902;font-style:italic">   *  参考：https://blog.csdn.net/topdeveloperr/article/details/88874957
</span><span style="color:#8f5902;font-style:italic">   *
</span><span style="color:#8f5902;font-style:italic">   *
</span><span style="color:#8f5902;font-style:italic">   * @author dmn
</span><span style="color:#8f5902;font-style:italic">   * @date 2021/5/19
</span><span style="color:#8f5902;font-style:italic">   */</span>
  <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">OnStackTest</span> <span style="color:#ce5c00;font-weight:bold">{</span>
      
      <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">User</span> <span style="color:#ce5c00;font-weight:bold">{</span>
          <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">id</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">String</span> <span style="color:#000">name</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;&#34;</span><span style="color:#ce5c00;font-weight:bold">;</span>
      <span style="color:#ce5c00;font-weight:bold">}</span>
  
      <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">alloc</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
          <span style="color:#000">User</span> <span style="color:#000">user</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">User</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#000">user</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">id</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">5</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#000">user</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">name</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;dmn&#34;</span><span style="color:#ce5c00;font-weight:bold">;</span>
      <span style="color:#ce5c00;font-weight:bold">}</span>
  
      <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">main</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#ce5c00;font-weight:bold">]</span> <span style="color:#000">args</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#204a87;font-weight:bold">throws</span> <span style="color:#000">InterruptedException</span> <span style="color:#ce5c00;font-weight:bold">{</span>
          <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">a</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#204a87;font-weight:bold">for</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">&lt;</span> <span style="color:#000">200000000</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
              <span style="color:#000">alloc</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#ce5c00;font-weight:bold">}</span>
          <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">b</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">b</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">a</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
      <span style="color:#ce5c00;font-weight:bold">}</span>
  <span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<p>以上代码执行结果如下，我们可以看到，执行完了，中间只出现过3次GC</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">  <span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#000">GC</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Allocation</span> <span style="color:#000">Failure</span><span style="color:#ce5c00;font-weight:bold">)</span>  <span style="color:#000">1023K</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#000">519K</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">5632K</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">0006984</span> <span style="color:#000">secs</span><span style="color:#ce5c00;font-weight:bold">]</span>
  <span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#000">GC</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Allocation</span> <span style="color:#000">Failure</span><span style="color:#ce5c00;font-weight:bold">)</span>  <span style="color:#000">1543K</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#000">567K</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">5632K</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">0011059</span> <span style="color:#000">secs</span><span style="color:#ce5c00;font-weight:bold">]</span>
  <span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#000">GC</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Allocation</span> <span style="color:#000">Failure</span><span style="color:#ce5c00;font-weight:bold">)</span>  <span style="color:#000">1591K</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#000">583K</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">5632K</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">0010251</span> <span style="color:#000">secs</span><span style="color:#ce5c00;font-weight:bold">]</span>
  <span style="color:#000">8</span></code></pre></div>
<p>而作为对比，我们如果将上述代码中的main方法改为如下：</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">      <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">main</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#ce5c00;font-weight:bold">]</span> <span style="color:#000">args</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#204a87;font-weight:bold">throws</span> <span style="color:#000">InterruptedException</span> <span style="color:#ce5c00;font-weight:bold">{</span>  
          <span style="color:#000">List</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">User</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">userList</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">ArrayList</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">User</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#204a87;font-weight:bold">for</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">&lt;</span> <span style="color:#000">200000000</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
              <span style="color:#000">User</span> <span style="color:#000">user</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">User</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
              <span style="color:#000">user</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">id</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">5</span><span style="color:#ce5c00;font-weight:bold">;</span>
              <span style="color:#000">user</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">name</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;dmn&#34;</span><span style="color:#ce5c00;font-weight:bold">;</span>
              <span style="color:#000">userList</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">add</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">user</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
              <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
          <span style="color:#ce5c00;font-weight:bold">}</span>
      <span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<p>执行的结果为如下，加了输出以后，可以看到，当集合加入了第240096个user对象以后，就发生了OutOfMemoryError了，说明内存最多放下240096个对象，不是内存够用。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">  [GC (Allocation Failure)  1023K-&gt;558K(5632K), 0.0007154 secs]
  [GC (Allocation Failure)  1580K-&gt;937K(5632K), 0.0015253 secs]
  [GC (Allocation Failure)  1961K-&gt;1667K(5632K), 0.0011996 secs]
  [GC (Allocation Failure)  2691K-&gt;2705K(6656K), 0.0015517 secs]
  [GC (Allocation Failure)  4753K-&gt;4378K(6656K), 0.0023053 secs]
  [Full GC (Ergonomics)  4378K-&gt;3657K(9728K), 0.0302245 secs]
  [GC (Allocation Failure)  4790K-&gt;4833K(8704K), 0.0056917 secs]
  [GC (Allocation Failure)  5857K-&gt;5907K(9216K), 0.0018717 secs]
  [GC (Allocation Failure)  6931K-&gt;6971K(9216K), 0.0022074 secs]
  [Full GC (Ergonomics)  6971K-&gt;6211K(9216K), 0.0428260 secs]
  [GC (Allocation Failure)  6981K-&gt;7139K(9216K), 0.0035979 secs]
  [Full GC (Ergonomics)  7139K-&gt;6981K(9216K), 0.0411045 secs]
  [GC (Allocation Failure)  6981K-&gt;6981K(9216K), 0.0008322 secs]
  [Full GC (Allocation Failure)  6981K-&gt;6963K(9216K), 0.0573462 secs]
  Exception in thread &#34;main&#34; java.lang.OutOfMemoryError: Java heap space
  	at java.util.Arrays.copyOf(Arrays.java:3210)
  	at java.util.Arrays.copyOf(Arrays.java:3181)
  	at java.util.ArrayList.grow(ArrayList.java:265)
  	at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:239)
  	at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:231)
  	at java.util.ArrayList.add(ArrayList.java:462)
  	at cn.shutdown.demo.OnStackTest.main(OnStackTest.java:57)
  
  Process finished with exit code 1
  </code></pre></div>
<p>但是很奇怪的是我去掉了<code>-XX:+DoEscapeAnalysis</code>和<code>-XX:+EliminateAllocations</code>两个jvm参数以后，执行的结果也还是一样，在配置较低的Linux服务器上面执行也是一样，没有像书中介绍的出现大量的GC日志。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">  去掉参数使用idea执行结果
  [GC (Allocation Failure)  1023K-&gt;533K(5632K), 0.0008148 secs]
  [GC (Allocation Failure)  1557K-&gt;597K(5632K), 0.0015174 secs]
  [GC (Allocation Failure)  1621K-&gt;597K(5632K), 0.0021861 secs]
  9</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">  在centos中执行去掉参数的结果
  [root@hdss7-188 temp]# java -server -Xmx10m -Xms10m -XX:+PrintGC -XX:-UseTLAB  OnStackTest
  [GC (Allocation Failure)  2751K-&gt;255K(9920K), 0.0006507 secs]
  [GC (Allocation Failure)  3007K-&gt;255K(9920K), 0.0003628 secs]
  [GC (Allocation Failure)  3007K-&gt;255K(9920K), 0.0001592 secs]
  16</code></pre></div>
<h1 id="4-方法区">4.方法区</h1>

<p>方法区是所有线程共享的内存区域，用于保存系统的类信息，类的字段、方法、常量池等。方法区大小决定系统可以保存多少个类。如果类太多可能导致方法区溢出而抛出内在溢出错误。</p>

<p>jdk1.6、jdk1.7中，方法区理解为永久区Perm。使用-XX:PermSize和-XX:MaxPermSize指定，默认-XX:MaxPermSize为64MB。如果使用了动态代理 ，可能会在运行时生成 大量的类，那就需要设置一个合理的永久区大小。</p>

<p>测试方法区代码：</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">java.util.HashMap</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#8f5902;font-style:italic">/**
</span><span style="color:#8f5902;font-style:italic"> * 测试方法区/永久区，
</span><span style="color:#8f5902;font-style:italic"> * 用1.7的jdk运行加以下参数
</span><span style="color:#8f5902;font-style:italic"> * -XX:PermSize=5m -XX:+PrintGCDetails -XX:MaxPermSize=5m
</span><span style="color:#8f5902;font-style:italic"> * 1.8的jdk运行加以下参数
</span><span style="color:#8f5902;font-style:italic"> * -XX:MaxMetaspaceSize=10m -XX:+PrintGCDetails
</span><span style="color:#8f5902;font-style:italic"> *
</span><span style="color:#8f5902;font-style:italic"> * @author domino
</span><span style="color:#8f5902;font-style:italic"> * @date 2021/5/20
</span><span style="color:#8f5902;font-style:italic"> */</span>
<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">PermTest</span> <span style="color:#ce5c00;font-weight:bold">{</span>

    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">main</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#ce5c00;font-weight:bold">]</span> <span style="color:#000">args</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">Map</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">Object</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">map</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">HashMap</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">put</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;id&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">Integer</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">class</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">put</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;name&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">class</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
           <span style="color:#8f5902;font-style:italic">//书上的数量是100000，但很快就正常运行完了，所以我把数量提升到了2000000000
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#204a87;font-weight:bold">for</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">&lt;</span> <span style="color:#000">2000000000</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                <span style="color:#000">CglibBean</span> <span style="color:#000">bean</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">CglibBean</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;cn.shutdown.demo.Permtest&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">catch</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Throwable</span> <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;total create count&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">finally</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;total create count&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">net.sf.cglib.beans.BeanGenerator</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">net.sf.cglib.beans.BeanMap</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">java.util.Iterator</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">java.util.Map</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">java.util.Set</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">CglibBean</span> <span style="color:#ce5c00;font-weight:bold">{</span>

    <span style="color:#5c35cc;font-weight:bold">@SuppressWarnings</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;unchecked&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">CglibBean</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Map</span> <span style="color:#000">propertyMap</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#000">Object</span> <span style="color:#000">object</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">generateBean</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">propertyMap</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">BeanMap</span> <span style="color:#000">beanMap</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">BeanMap</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">create</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">object</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#5c35cc;font-weight:bold">@SuppressWarnings</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;unchecked&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">private</span> <span style="color:#000">Object</span> <span style="color:#000">generateBean</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Map</span> <span style="color:#000">propertyMap</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#000">BeanGenerator</span> <span style="color:#000">generator</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">BeanGenerator</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">Set</span> <span style="color:#000">keySet</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">propertyMap</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">keySet</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">for</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Iterator</span> <span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">keySet</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">iterator</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">hasNext</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">String</span> <span style="color:#000">key</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">next</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">generator</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">addProperty</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Class</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#000">propertyMap</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">generator</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">create</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span> </code></pre></div>
<p>cglib依赖，不能用太高的版本，太高的版本不支持1.7的jdk。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">        &lt;dependency&gt;
            &lt;groupId&gt;cglib&lt;/groupId&gt;
            &lt;artifactId&gt;cglib-nodep&lt;/artifactId&gt;
            &lt;version&gt;2.2.2&lt;/version&gt;
        &lt;/dependency&gt;</code></pre></div>
<p>因为我的本机的jdk是1.8版本，已经移除了永久区，所以使用<code>-XX:MaxMetaspaceSize=10m -XX:+PrintGCDetails</code> 的参数去运行，但是100000的数量很快就执行完了，执行的结果如下。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>GC <span style="color:#ce5c00;font-weight:bold">(</span>Allocation Failure<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">[</span>PSYoungGen: 65536K-&gt;1042K<span style="color:#ce5c00;font-weight:bold">(</span>76288K<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">]</span> 65536K-&gt;1050K<span style="color:#ce5c00;font-weight:bold">(</span>251392K<span style="color:#ce5c00;font-weight:bold">)</span>, 0.0025167 secs<span style="color:#ce5c00;font-weight:bold">]</span> <span style="color:#ce5c00;font-weight:bold">[</span>Times: <span style="color:#000">user</span><span style="color:#ce5c00;font-weight:bold">=</span>0.01 <span style="color:#000">sys</span><span style="color:#ce5c00;font-weight:bold">=</span>0.01, <span style="color:#000">real</span><span style="color:#ce5c00;font-weight:bold">=</span>0.00 secs<span style="color:#ce5c00;font-weight:bold">]</span> 
<span style="color:#ce5c00;font-weight:bold">[</span>GC <span style="color:#ce5c00;font-weight:bold">(</span>Allocation Failure<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">[</span>PSYoungGen: 66578K-&gt;656K<span style="color:#ce5c00;font-weight:bold">(</span>76288K<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">]</span> 66586K-&gt;672K<span style="color:#ce5c00;font-weight:bold">(</span>251392K<span style="color:#ce5c00;font-weight:bold">)</span>, 0.0028107 secs<span style="color:#ce5c00;font-weight:bold">]</span> <span style="color:#ce5c00;font-weight:bold">[</span>Times: <span style="color:#000">user</span><span style="color:#ce5c00;font-weight:bold">=</span>0.01 <span style="color:#000">sys</span><span style="color:#ce5c00;font-weight:bold">=</span>0.00, <span style="color:#000">real</span><span style="color:#ce5c00;font-weight:bold">=</span>0.00 secs<span style="color:#ce5c00;font-weight:bold">]</span> 
total create count100000
Heap
 PSYoungGen      total 76288K, used 30148K <span style="color:#ce5c00;font-weight:bold">[</span>0x00000007aa900000, 0x00000007b3e00000, 0x00000007ffe00000<span style="color:#ce5c00;font-weight:bold">)</span>
  eden space 65536K, 45% used <span style="color:#ce5c00;font-weight:bold">[</span>0x00000007aa900000,0x00000007ac5cd130,0x00000007ae900000<span style="color:#ce5c00;font-weight:bold">)</span>
  from space 10752K, 6% used <span style="color:#ce5c00;font-weight:bold">[</span>0x00000007af380000,0x00000007af424010,0x00000007afe00000<span style="color:#ce5c00;font-weight:bold">)</span>
  to   space 10752K, 0% used <span style="color:#ce5c00;font-weight:bold">[</span>0x00000007ae900000,0x00000007ae900000,0x00000007af380000<span style="color:#ce5c00;font-weight:bold">)</span>
 ParOldGen       total 175104K, used 16K <span style="color:#ce5c00;font-weight:bold">[</span>0x00000006ffe00000, 0x000000070a900000, 0x00000007aa900000<span style="color:#ce5c00;font-weight:bold">)</span>
  object space 175104K, 0% used <span style="color:#ce5c00;font-weight:bold">[</span>0x00000006ffe00000,0x00000006ffe04000,0x000000070a900000<span style="color:#ce5c00;font-weight:bold">)</span>
 Metaspace       used 3822K, capacity 5028K, committed 5120K, reserved 1056768K
  class space    used 418K, capacity 458K, committed 512K, reserved 1048576K

Process finished with <span style="color:#204a87">exit</span> code <span style="color:#0000cf;font-weight:bold">0</span></code></pre></div>
<p>这不行啊，没整出来活啊，我得要他溢出啊，他没溢啊，然后我就将循环的数量提升到了2000000000（多少个零自己数去）。然后用<code>Run With VisualVM</code>来运行，在监控的图里面去看元数据区里面的内存占用效果。结果跑了好长的时间，分配 的10M元数据区的内存也还是没溢出(这里书上要求是设置5M的，但估计是因为我的系统和jdk都是64位的，所以IDE提示5M内存太小，然后我试着的结果是最小10M)。</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/1621675948682-20210522173228.png" width = 300 /> </div>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/1621676104977-20210522173503.png" width = 600 /> </div>

<p>然后就想试试1.7是什么效果，因为电脑只装了1.8，所以就去官网去下载jdk1.7，结果，好家伙，jdk1.7不提供下载了，官网的大概意思是，jdk1.7只提供给付了支持费的用户下载，还要提单子，于是找了别的下载，安装到电脑上面。<a href="https://pan.baidu.com/s/1SQiidrPFF5aZr4xlx0ekoQ">jdk1.7百度盘下载链接</a></p>

<p>Idea上面配置了jdk1.7以后，将demo项目的编译jdk配置为1.7，PermTest类的jre也指定1.7进行运行。</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/1621673908770-20210522165826.png" width = 600 /> </div>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/1621673967002-20210522165925.png" width = 600 /> </div>

<p>然后再运行项<code>PermTest</code>代码</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">public class PermTest {

    public static void main(String[] args) {
        int i = 0;
        try {
            for (i = 0; i &lt; 10000000; i++) {
                CglibBean bean = new CglibBean(&#34;cn.shutdown.demo.Permtest&#34; + i, new HashMap());
            }
        } catch (Throwable e) {
            System.out.println(&#34;total create count&#34; + i);
        } finally {
            System.out.println(&#34;total create count&#34; + i);
        }
    }
}</code></pre></div>
<p>好家伙，按 <code>-XX:PermSize=5m -XX:+PrintGCDetails -XX:MaxPermSize=5m</code>这个参数去执行竟然正常的执行完了。也没有出现永久区溢出的情况。也许是现在的电脑比起作者写书的时候的电脑的性能强悍的太多了？</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">[GC [PSYoungGen: 66048K-&gt;1003K(76800K)] 66048K-&gt;1011K(251392K), 0.0021120 secs] [Times: user=0.02 sys=0.00, real=0.00 secs] 
[GC [PSYoungGen: 67051K-&gt;576K(76800K)] 67059K-&gt;592K(251392K), 0.0020370 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
[GC [PSYoungGen: 66624K-&gt;624K(76800K)] 66640K-&gt;640K(251392K), 0.0008780 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
[GC [PSYoungGen: 66672K-&gt;640K(142848K)] 66688K-&gt;656K(317440K), 0.0014140 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 
[GC [PSYoungGen: 132736K-&gt;640K(142848K)] 132752K-&gt;656K(317440K), 0.0042810 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 
[GC [PSYoungGen: 132736K-&gt;528K(265216K)] 132752K-&gt;552K(439808K), 0.0020670 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
[GC [PSYoungGen: 196752K-&gt;320K(265216K)] 196776K-&gt;816K(439808K), 0.0026410 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
[Full GC [PSYoungGen: 320K-&gt;0K(265216K)] [ParOldGen: 496K-&gt;489K(95232K)] 816K-&gt;489K(360448K) [PSPermGen: 4095K-&gt;4094K(4096K)], 0.0140030 secs] [Times: user=0.03 sys=0.01, real=0.02 secs] 
....略过一部分日志....
Heap
 PSYoungGen      total 563200K, used 5749K [0x00000007aaa80000, 0x00000007cd780000, 0x0000000800000000)
  eden space 562176K, 1% used [0x00000007aaa80000,0x00000007ab01d460,0x00000007ccf80000)
  from space 1024K, 0% used [0x00000007ccf80000,0x00000007ccf80000,0x00000007cd080000)
  to   space 1024K, 0% used [0x00000007cd680000,0x00000007cd680000,0x00000007cd780000)
 ParOldGen       total 1104896K, used 427K [0x0000000700000000, 0x0000000743700000, 0x00000007aaa80000)
  object space 1104896K, 0% used [0x0000000700000000,0x000000070006ae98,0x0000000743700000)
 PSPermGen       total 4096K, used 4094K [0x00000006ffc00000, 0x0000000700000000, 0x0000000700000000)
  object space 4096K, 99% used [0x00000006ffc00000,0x00000006fffffa90,0x0000000700000000)

Process finished with exit code 0</code></pre></div>
<p>然后我再调小参数，使用<code>-XX:PermSize=3m -XX:+PrintGCDetails -XX:MaxPermSize=1m</code>，然后内存终于溢出了，报出了<code>PermGen space</code> ，这也就是方法区(永久区)溢出了。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">[GC [PSYoungGen: 2642K-&gt;384K(76800K)] 2642K-&gt;384K(251392K), 0.0015940 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
[Full GC [PSYoungGen: 384K-&gt;0K(76800K)] [ParOldGen: 0K-&gt;182K(122368K)] 384K-&gt;182K(199168K) [PSPermGen: 2047K-&gt;2046K(2048K)], 0.0079460 secs] [Times: user=0.02 sys=0.00, real=0.01 secs] 
[GC [PSYoungGen: 1321K-&gt;32K(94208K)] 1503K-&gt;214K(216576K), 0.0008100 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC [PSYoungGen: 32K-&gt;0K(94208K)] [ParOldGen: 182K-&gt;182K(232448K)] 214K-&gt;182K(326656K) [PSPermGen: 2047K-&gt;2047K(2048K)], 0.0051070 secs] [Times: user=0.02 sys=0.00, real=0.01 secs] 
[GC [PSYoungGen: 0K-&gt;0K(120832K)] 182K-&gt;182K(353280K), 0.0012080 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC [PSYoungGen: 0K-&gt;0K(120832K)] [ParOldGen: 182K-&gt;172K(351744K)] 182K-&gt;172K(472576K) [PSPermGen: 2047K-&gt;2047K(2048K)], 0.0058910 secs] [Times: user=0.02 sys=0.00, real=0.00 secs] 
[GC [PSYoungGen: 2201K-&gt;32K(132608K)] 2374K-&gt;204K(484352K), 0.0004310 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC [PSYoungGen: 32K-&gt;0K(132608K)] [ParOldGen: 172K-&gt;172K(537600K)] 204K-&gt;172K(670208K) 
....省略部分日志....
Error occurred during initialization of VM
java.lang.OutOfMemoryError: PermGen space
	at sun.misc.Launcher.&lt;init&gt;(Launcher.java:71)
	at sun.misc.Launcher.&lt;clinit&gt;(Launcher.java:57)
	at java.lang.ClassLoader.initSystemClassLoader(ClassLoader.java:1489)
	at java.lang.ClassLoader.getSystemClassLoader(ClassLoader.java:1474)</code></pre></div>
    </div>
    <footer class="post-footer">
     

     <div class="post-nav">
    <div class="post-nav-next post-nav-item">
    
        <a href="http://www.shutdown.cn/post/jvm/" rel="next" title="">
        <i class="fa fa-chevron-left"></i> 
        </a>
    
    </div>

    <div class="post-nav-prev post-nav-item">
    
        <a href="http://www.shutdown.cn/post/jvm%E5%AD%A6%E4%B9%A003-%E5%B8%B8%E7%94%A8java%E8%99%9A%E6%8B%9F%E6%9C%BA%E5%8F%82%E6%95%B0/" rel="prev" title="">
         <i class="fa fa-chevron-right"></i>
        </a>
    
    </div>
</div>
      
     
     
     






    </footer>
  </article>
</section>

          </div>
        </div>
        <div class="sidebar-toggle">
  <div class="sidebar-toggle-line-wrap">
    <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
  </div>
</div>
<aside id="sidebar" class="sidebar">
  <div class="sidebar-inner">

    <section class="site-overview sidebar-panel  sidebar-panel-active ">
      <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
        src="http://www.shutdown.cn/img/author.jpg"
        alt="不与天斗Domino" />
    <p class="site-author-name" itemprop="name">不与天斗Domino</p>
    <p class="site-description motion-element" itemprop="description"> 
        Programmer &amp; Architect</p>
</div>
      <nav class="site-state motion-element">
    <div class="site-state-item site-state-posts">
      <a href="http://www.shutdown.cn/post/">
        <span class="site-state-item-count">172</span>
        <span class="site-state-item-name">日志</span>
      </a>
    </div>
    <div class="site-state-item site-state-categories">    
        <a href="http://www.shutdown.cn/categories/">      
         
        <span class="site-state-item-count">10</span>
        
        <span class="site-state-item-name">分类</span>
        
        </a>
    </div>

    <div class="site-state-item site-state-tags">
        <a href="http://www.shutdown.cn/tags/">
         
        <span class="site-state-item-count">96</span>
        
        <span class="site-state-item-name">标签</span>
        </a>
    </div>
</nav>
      
      

      

      <div class="links-of-blogroll motion-element inline">
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=&amp;m=0&amp;s=220&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33&amp;bv=35" async="async"></script>
</div>

    </section>
    
  </div>
</aside>

      </div>
    </main>
   
    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  <span itemprop="copyrightYear">  &copy; 
  2013 - 2022</span>
  <span class="with-love"><i class="fa fa-heart"></i></span>
  <span class="author" itemprop="copyrightHolder">天地维杰网</span>
  <span class="icp" itemprop="copyrightHolder"><a href="https://beian.miit.gov.cn/" target="_blank">京ICP备13019191号-1</a></span>
</div>
<div class="powered-by">
  Powered by - <a class="theme-link" href="http://gohugo.io" target="_blank" title="hugo" >Hugo v0.63.2</a>
</div>
<div class="theme-info">
  Theme by - <a class="theme-link" href="https://github.com/xtfly/hugo-theme-next" target="_blank"> NexT
  </a>
</div>


      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
      <span id="scrollpercent"><span>0</span>%</span>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery/index.js?v=2.1.3"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/fastclick/lib/fastclick.min.js?v=1.0.6"></script> 
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.min.js?v=1.2.1"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="http://www.shutdown.cn/js/vendor/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>

<script src="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.pack.js?v=2.1.5"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/utils.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/motion.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/affix.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/schemes/pisces.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/scrollspy.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/post-details.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/toc.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/bootstrap.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'] ],
      displayMath: [ ['$$','$$'] ],
      processEscapes: true
    },
    "HTML-CSS": { fonts: ["TeX"] }
  });
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML' async></script>
</body>
</html>